package com.cq.hd.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cq.hd.common.utils.BeanUtils;
import com.cq.hd.order.api.dto.OrderItemDto;
import com.cq.hd.order.api.vo.MerchantOrderAmtStatVo;
import com.cq.hd.order.api.vo.OrderItemVo;
import com.cq.hd.order.mapper.TbOrderItemMapper;
import com.cq.hd.order.po.TbOrderItemPo;
import com.cq.hd.order.service.TbOrderItemService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * 订单项表 服务实现类
 * </p>
 *
 * @author mYunYu
 * @since 2023-12-13
 */
@Service
public class TbOrderItemServiceImpl extends ServiceImpl<TbOrderItemMapper, TbOrderItemPo> implements TbOrderItemService {

    @Override
    public List<OrderItemVo> listByActiveIds(List<Long> activeIds) {
        return baseMapper.listByActiveIds(activeIds);
    }

    @Override
    public List<OrderItemVo> listByDto(OrderItemDto orderItemDto) {
        return baseMapper.listByDto(orderItemDto);
    }

    @Override
    public OrderItemVo getByVerifyCode(String verifyCode) {
        List<TbOrderItemPo> orderItemPos = baseMapper.selectList(new QueryWrapper<TbOrderItemPo>().eq("del_state", 0).eq("verify_code", verifyCode));
        if (!CollectionUtils.isEmpty(orderItemPos)) {
            TbOrderItemPo tbOrderItemPo = orderItemPos.get(0);
            OrderItemVo orderItemVo = new OrderItemVo();
            BeanUtils.copyProperties(tbOrderItemPo, orderItemVo);
            return orderItemVo;
        }
        return null;
    }

    @Override
    public MerchantOrderAmtStatVo getMerchantWaitSettleAmt(Long merchantId) {
        return baseMapper.sumMerchantWaitSettleAmt(merchantId);
    }

}
